package cn.practice.chat.qiniu.service;

import cn.practice.chat.lang.Result;
import cn.practice.chat.qiniu.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @ClassName QiniuUpload
 * @Description: /qiniu/upload 文件上传七牛云
 * @Author A-TAO
 * @Date 2022/11/18
 * @Version V1.0
 **/
@RestController
@RequestMapping("/qiniu")
public class QiniuUpload {


    @Autowired
    private QiniuUtils qiniuUtils;

    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws IOException {
        if(file == null){
            return Result.error("请选择要上传的文件");
        }

        String url = qiniuUtils.uploadFile(file);
        return Result.success(url);
    }

}
